package Text_50;

public class Code {

	public static void main(String[] args) {
		Musician m = new Musician("张三",22);
        Piano p = new Piano();
        Guitar g = new Guitar();
        m.playInstrument(p);
        p.play();
        m.stopInstrument(g);
        g.stopPlaying();
    }
}
interface  Instrument{
    void play();
    void stopPlaying();
}
class Piano implements Instrument {

    @Override
    public void play() {
        System.out.println(this.toString()+"发出悦耳的音乐");
    }

    @Override
    public void stopPlaying() {
        System.out.println(this.toString()+"不发出声音了");
    }

    @Override
    public String toString() {
        return "钢琴";
    }
}
class Guitar implements  Instrument{

    @Override
    public void play() {
        System.out.println(this.toString()+"发出悦耳的音乐");
    }

    @Override
    public void stopPlaying() {
        System.out.println(this.toString()+"不发出声音了");
    }

    @Override
    public String toString() {
        return "吉他";
    }
}
class Musician{
    private String name;
    private int age;
    public Musician(String name,int age){
        this.name = name;
        this.age = age;
    }
    public void playInstrument(Instrument ins){
        System.out.println(age+"岁的音乐家"+name+"正在弹"+ins.toString());

    }
    public void stopInstrument(Instrument ins){
        System.out.println(age+"岁的音乐家"+name+"停止弹"+ins.toString());
    }
}

